home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Workbench Design
/
WB Collection.iso
/
workbench werkzeuge
/
boot tools
/
rand
/
rand.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-07
|
926b
|
48 lines
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#define LINELENGTH 132
int main(int argc, char *argv[])
{
long r, line = 0, lines = 0;
FILE *cfile;
char *buffer = (char *) malloc(LINELENGTH);
if (argc > 1)
{
if (!(cfile = fopen(argv[1], "r")))
{
printf("%s: Couldn't open file, \"%s\".\n", argv[0], argv[1]);
exit(3);
}
}
else if (!(cfile = fopen("s:random-sequences", "r")))
{
printf("%s: Couldn't open file, \"s:random-sequences\".\n", argv[0]);
exit(3);
}
while (fgets(buffer, LINELENGTH, cfile) != NULL) lines++;
srand(time(NULL));
r = rand() % lines;
fseek(cfile, 0, SEEK_SET);
while (fgets(buffer, LINELENGTH, cfile) != NULL)
{
if (line++ >= r && strlen(buffer) < LINELENGTH)
{
system(buffer);
break;
}
}
fclose(cfile);
free(buffer);
}